package o;

import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.hmf.orb.exception.ConnectRemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.biu.a;
import o.fho.b;

public class bim {

    public interface c {
        void ॱ(List<String> list);
    }

    public static ArrayList<String> ˏ(GameInfo gameInfo, boolean z) {
        if (gameInfo == null) {
            Logger.e("PermanentEnterSupport", "getPermanentServiceList error, gameInfo == null");
            return new ArrayList();
        }
        ArrayList<String> ˊॱ = biu.ˋ().ˊॱ();
        Collection ˋ = ˋ(gameInfo, z);
        if (CollectCheck.isEmpty(ˋ)) {
            ˊॱ.clear();
        } else if (!CollectCheck.isEmpty(ˊॱ)) {
            ˊॱ.retainAll(ˋ);
        } else if (ˋ.size() > 7) {
            ˊॱ.addAll(ˋ.subList(0, 6));
        } else {
            ˊॱ.addAll(ˋ);
        }
        ˊॱ.add("all_service");
        return ˊॱ;
    }

    public static ArrayList<a> ˊ(GameInfo gameInfo, boolean z) {
        if (gameInfo == null) {
            Logger.e("PermanentEnterSupport", "getPermanentAppList error, gameInfo == null");
            return new ArrayList();
        } else if (big.ˏ()) {
            ArrayList<a> ͺ = biu.ˋ().ͺ();
            if (CollectCheck.isEmpty(ͺ)) {
                if (z) {
                    Logger.ˎ("PermanentEnterSupport", "offline , no cache , dont show permanent app.");
                    ͺ = new ArrayList();
                } else {
                    Logger.ˎ("PermanentEnterSupport", "getGssAppList");
                    ͺ = bib.ˏ(gameInfo);
                }
                if (ͺ.size() > 7) {
                    ͺ = new ArrayList(ͺ.subList(0, 7));
                }
                ͺ.add(a.ˏ("all_app", null, null, null));
                return ͺ;
            }
            Logger.ˎ("PermanentEnterSupport", "exist local permanent app");
            return ͺ;
        } else {
            Logger.ˎ("PermanentEnterSupport", "rom not support freeform");
            return new ArrayList();
        }
    }

    public static List<String> ˋ(GameInfo gameInfo, boolean z) {
        List<String> arrayList = new ArrayList();
        if (gameInfo == null) {
            return arrayList;
        }
        if (z) {
            return bii.ˎ(gameInfo);
        }
        ezo ˋ = ezs.ˏ().ˋ(gameInfo);
        if (ˋ == null) {
            return arrayList;
        }
        List<bfo> ˎ = ˋ.ˎ();
        if (ˎ.isEmpty()) {
            return arrayList;
        }
        for (bfo ˎ2 : ˎ) {
            List<String> ˏ;
            if ("buoy_gss|all_service".equals(ˎ2.ˎ())) {
                ˏ = big.ˏ(gameInfo);
            } else {
                ˏ = arrayList;
            }
            arrayList = ˏ;
        }
        return arrayList;
    }

    public static void ॱ(Context context, GameInfo gameInfo, c cVar, boolean z) {
        if (context != null && gameInfo != null && cVar != null) {
            final List ˏ = ˏ(gameInfo, z);
            ˎ(ˏ, gameInfo);
            if (ˋ(ˏ)) {
                final ffa o_ffp = new ffp(context, "com.huawei.gameassistant");
                final c cVar2 = cVar;
                final Context context2 = context;
                final GameInfo gameInfo2 = gameInfo;
                fho.ˋ(o_ffp, new b() {
                    public void ˏ(ffd o_ffd, ConnectRemoteException connectRemoteException) {
                        if (connectRemoteException != null) {
                            bim.ॱ(ˏ);
                            cVar2.ॱ(ˏ);
                            return;
                        }
                        fhz ˋ = o_ffd.ˋ("buoysettingmodule");
                        if (ˋ == null) {
                            bim.ॱ(ˏ);
                            cVar2.ॱ(ˏ);
                            return;
                        }
                        eyb o_eyb = (eyb) ˋ.ॱ(eyb.class);
                        if (o_eyb == null) {
                            bim.ॱ(ˏ);
                            cVar2.ॱ(ˏ);
                            return;
                        }
                        bim.ˋ(o_eyb, ˏ);
                        bim.ˋ(context2, o_eyb, ˏ);
                        bim.ˊ(o_eyb, ˏ, gameInfo2, cVar2);
                        o_ffp.ॱ();
                    }
                });
                return;
            }
            cVar.ॱ(ˏ);
        }
    }

    private static void ˊ(@NonNull eyb o_eyb, @NonNull final List<String> list, @NonNull final GameInfo gameInfo, @NonNull final c cVar) {
        if (list.contains("net_optim")) {
            o_eyb.ˋ(gameInfo.getPackageName()).ˏ(new fjq<Boolean>() {
                public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                    if (!o_fjo_java_lang_Boolean.ˊ()) {
                        list.remove("net_optim");
                    } else if (((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                        biu.ˋ().ˏ(gameInfo, true);
                    } else {
                        list.remove("net_optim");
                        biu.ˋ().ˏ(gameInfo, false);
                    }
                    cVar.ॱ(list);
                }
            });
        } else {
            cVar.ॱ(list);
        }
    }

    private static void ˋ(@NonNull Context context, @NonNull eyb o_eyb, @NonNull List<String> list) {
        try {
            if (context.getResources().getConfiguration().orientation == 1 || !o_eyb.ˎ()) {
                Logger.ˎ("PermanentEnterSupport", "!windowManager.isSupportSideButton()");
                list.remove("virtual_key_setting");
                biu.ˋ().ˋ(false);
                return;
            }
            biu.ˋ().ˋ(true);
        } catch (Exception e) {
            list.remove("virtual_key_setting");
            biu.ˋ().ˋ(false);
            Logger.e("PermanentEnterSupport", "isSupportSideButton exception");
        }
    }

    private static void ˋ(@NonNull eyb o_eyb, @NonNull List<String> list) {
        if (o_eyb.ˏ()) {
            biu.ˋ().ˎ(true);
            return;
        }
        list.remove("device_setting");
        biu.ˋ().ˎ(false);
    }

    private static void ˎ(@NonNull List<String> list, GameInfo gameInfo) {
        if (list.contains("sound_to_vibrate_effect") && !big.ˎ(gameInfo)) {
            list.remove("sound_to_vibrate_effect");
        }
    }

    private static boolean ˋ(List<String> list) {
        if (CollectCheck.isEmpty(list)) {
            return false;
        }
        if (list.contains("device_setting") || list.contains("net_optim") || list.contains("virtual_key_setting")) {
            return true;
        }
        return false;
    }

    private static void ॱ(@NonNull List<String> list) {
        list.remove("device_setting");
        list.remove("net_optim");
        list.remove("virtual_key_setting");
    }

    public static boolean ॱ(Object obj) {
        if (obj instanceof String) {
            return TextUtils.isEmpty((String) obj);
        }
        if (obj instanceof a) {
            return TextUtils.isEmpty(((a) obj).ˊ());
        }
        return true;
    }
}
